﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace 雷赛板卡上位机.Models
{
    public class AxisFeedBackValueModel : INotifyPropertyChanging
    {
        string axisName;
        double feedbackPosition;
        double feedbackSpeed;
        int axisStatus;
        int axisError;


        public AxisFeedBackValueModel(string axisName)
        {
            AxisName = axisName ?? throw new ArgumentNullException(nameof(axisName));
        }

        public double FeedbackPosition
        {
            get => feedbackPosition;
            set
            {
                feedbackPosition = value;
                OnPropertyChanging();
            }
        }
        public double FeedbackSpeed
        {
            get => feedbackSpeed;
            set
            {
                feedbackSpeed = value;
                OnPropertyChanging();
            }
        }
        public int AxisStatus
        {
            get => axisStatus;
            set
            {
                axisStatus = value;
                OnPropertyChanging();
            }
        }
        public int AxisError
        {
            get => axisError;
            set
            {
                axisError = value;
                OnPropertyChanging();
                OnPropertyChanging(nameof(IsAxisError));
            }
        }

        public string AxisName
        {
            get => axisName; 
            set
            {
                axisName = value;
                OnPropertyChanging();
            }
        }

        public bool IsAxisError =>AxisError == 0;
        public event PropertyChangingEventHandler? PropertyChanging;

        protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
        {
            ArgumentNullException.ThrowIfNull(e);

            PropertyChanging?.Invoke(this, e);
        }
        protected void OnPropertyChanging([CallerMemberName] string? propertyName = null)
        {

            OnPropertyChanging(new PropertyChangingEventArgs(propertyName));
        }
    }
}
